package com.hh.service.Impl;

import com.hh.dto.ResultDTO;
import com.hh.mapper.CoachMapper;
import com.hh.model.CoachModel;
import com.hh.service.CoachService;
import com.hh.until.JSONCopy;
import com.hh.vo.CoachVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoachServiceImpl implements CoachService {
    @Autowired
    private CoachMapper coachMapper;

    @Override
    public ResultDTO add(CoachVO CoachVO) {
        CoachModel coachModel = JSONCopy.copy(CoachVO, CoachModel.class);
        return ResultDTO.getDto(coachMapper.add(coachModel), null);
    }

    @Override
    public ResultDTO delete(CoachVO CoachVO) {
        CoachModel coachModel = JSONCopy.copy(CoachVO, CoachModel.class);
        return ResultDTO.getDto(coachMapper.delete(coachModel), null);
    }

    @Override
    public ResultDTO update(CoachVO CoachVO) {
        CoachModel coachModel = JSONCopy.copy(CoachVO, CoachModel.class);
        return ResultDTO.getDto(coachMapper.update(coachModel), null);
    }

    @Override
    public ResultDTO findAll(CoachVO CoachVO) {
        CoachModel coachModel = JSONCopy.copy(CoachVO, CoachModel.class);
        coachModel.setPage((coachModel.getPage()-1)*coachModel.getLimit());
        List<CoachModel> CoachModelList = coachMapper.findAll(coachModel);
        return ResultDTO.getDto(coachMapper.count(coachModel), CoachModelList);
    }

    @Override
    public ResultDTO findById(CoachVO CoachVO) {
        CoachModel coachModel = JSONCopy.copy(CoachVO, CoachModel.class);
        return ResultDTO.getDto(0, coachMapper.findById(coachModel));
    }

    @Override
    public ResultDTO count(CoachVO CoachVO) {
        CoachModel coachModel = JSONCopy.copy(CoachVO, CoachModel.class);
        return ResultDTO.getDto(coachMapper.count(coachModel), null);
    }
}
